package com.osilon.updater.tasks;


import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;

import com.osilon.asm.InsnSearcher;
import com.osilon.asm.OsilonClassNode;
import com.osilon.updater.Updater;
import com.osilon.util.ClassCache;

public class InitTask extends Task {
	public boolean canProcess(OsilonClassNode node) {
		return node.name.equals("net/minecraft/server/MinecraftServer");
	}
	
	public void process(ClassCache cache, OsilonClassNode node) {
		node.interfaces.add("com/osilon/hooks/MinecraftServer");
		for(MethodNode mn : node.static_methods) {
			if(mn.name.equals("main")) {
				InsnSearcher searcher = new InsnSearcher(mn);
				searcher.nextLdc("Server thread");
				
				MethodInsnNode min = searcher.nextInvoke(Opcodes.INVOKESPECIAL);
				
				Updater.getInfoMap().put("ServerThread", min.owner);
			}
		}
	}
}
